<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:c="livcos.org/ns/cosmos"
  xmlns:f="livcos.org/ns/xslt/function"
  xmlns="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="c f">

	<xsl:import href="/livcos.org/common/base.xsl"/>
	
	<xsl:variable name="viewObjId" select="'aaaaa'"/>
	
  <xsl:template match="/">
    <html>
      <body>
        <table>
          <tr>
            <th>Test Case</th>
            <th>Expected</th>
            <th>Value</th>
          </tr>
        	<tr>
        		<td>Current Time</td>
        		<td>&#160;</td>
        		<td>
        			<xsl:value-of select="current-dateTime()"/>
        		</td>
        	</tr>
        	<xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'LivCos Version'"/>
        		<xsl:with-param name="exp_regExp" select="'^[0-9]+(\.[0-9]+)+$'"/>
        		<xsl:with-param name="val" select="$livcos_version"/>
          </xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Caller Object ID'"/>
        		<xsl:with-param name="exp" select="'/test.livcos.org/web/common/test_base'"/>
        		<xsl:with-param name="val" select="$callerObjId"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Caller Base Object ID'"/>
        		<xsl:with-param name="exp" select="'/test.livcos.org/web'"/>
        		<xsl:with-param name="val" select="$callerBaseId"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Caller Object Name'"/>
        		<xsl:with-param name="exp" select="'common/test_base'"/>
        		<xsl:with-param name="val" select="$callerObjName"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'to root path'"/>
        		<xsl:with-param name="exp" select="'../../..'"/>
        		<xsl:with-param name="val" select="$toRootPath"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Job ID'"/>
        		<xsl:with-param name="exp_regExp" select="'^job_.*'"/>
        		<xsl:with-param name="val" select="$jobId"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Job Definition Object ID'"/>
        		<xsl:with-param name="exp" select="'/test.livcos.org/web/common/test_base'"/>
        		<xsl:with-param name="val" select="$jobDefId"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Task Definition Object ID'"/>
        		<xsl:with-param name="exp" select="'/test.livcos.org/web/common/test_base'"/>
        		<xsl:with-param name="val" select="$taskDefId"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'base-uri()'"/>
        		<xsl:with-param name="exp_regExp" select="'^cosmos:/localhost/system/work/job_.*'"/>
        		<xsl:with-param name="val" select="base-uri()"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'static-base-uri()'"/>
        		<xsl:with-param name="exp" select="'cosmos:/test.livcos.org/web/common/test_base'"/>
        		<xsl:with-param name="val" select="static-base-uri()"/>
        	</xsl:call-template>
        	<xsl:variable name="cosmosObj" select="doc('/cosmos.meta2')/*"/>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Cosmos Object ID'"/>
        		<xsl:with-param name="exp_regExp" select="'^/cosmos'"/>
        		<xsl:with-param name="val" select="f:object-id($cosmosObj)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Cosmos Relative Name (relative to base-uri())'"/>
        		<xsl:with-param name="exp_regExp" select="'^cosmos'"/>
        		<xsl:with-param name="val" select="f:object-relative-name($cosmosObj)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Cosmos Name'"/>
        		<xsl:with-param name="exp_regExp" select="'^cosmos'"/>
        		<xsl:with-param name="val" select="f:object-name($cosmosObj)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'This Object ID'"/>
        		<xsl:with-param name="exp_regExp" select="'^/localhost/system/work/job_'"/>
        		<xsl:with-param name="val" select="f:object-id(.)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'This Object Relative Name (relative to base-uri())'"/>
        		<xsl:with-param name="exp_regExp" select="'^job_'"/>
        		<xsl:with-param name="val" select="f:object-relative-name(.)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'This Object Name'"/>
        		<xsl:with-param name="exp_regExp" select="'^job_'"/>
        		<xsl:with-param name="val" select="f:object-name(.)"/>
        	</xsl:call-template>
        	<xsl:variable name="dataObj" select="doc('../../data.cosmos')/*"/>
          <xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'''data'' Object ID'"/>
            <xsl:with-param name="exp" select="'/test.livcos.org/data'"/>
            <xsl:with-param name="val" select="f:object-id($dataObj)"/>
          </xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'''data'' Object Relative Name (relative to base-uri())'"/>
        		<xsl:with-param name="exp" select="'data'"/>
        		<xsl:with-param name="val" select="f:object-relative-name($dataObj)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'''data'' Object Name'"/>
        		<xsl:with-param name="exp" select="'data'"/>
        		<xsl:with-param name="val" select="f:object-name($dataObj)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'''data/unit'' Object ID'"/>
            <xsl:with-param name="exp" select="'/test.livcos.org/data/unit'"/>
            <xsl:with-param name="val" select="f:object-id($dataObj/c:unit)"/>
          </xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'''data/unit'' Object Relative Name (relative to base-uri())'"/>
        		<xsl:with-param name="exp" select="'data/unit'"/>
        		<xsl:with-param name="val" select="f:object-relative-name($dataObj/c:unit)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'''data/unit'' Object Name'"/>
        		<xsl:with-param name="exp" select="'unit'"/>
        		<xsl:with-param name="val" select="f:object-name($dataObj/c:unit)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'''data/unit/sys/status'' Object ID'"/>
            <xsl:with-param name="exp" select="'/test.livcos.org/data/unit/sys/status'"/>
            <xsl:with-param name="val" select="f:object-id($dataObj/c:unit/c:sys/c:status)"/>
          </xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'''data/unit/sys/status'' Object Relative Name (relative to base-uri())'"/>
        		<xsl:with-param name="exp" select="'data/unit/sys/status'"/>
        		<xsl:with-param name="val" select="f:object-relative-name($dataObj/c:unit/c:sys/c:status)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'''data/unit/sys/status'' Object Name'"/>
        		<xsl:with-param name="exp" select="'status'"/>
        		<xsl:with-param name="val" select="f:object-name($dataObj/c:unit/c:sys/c:status)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'''data/unit/sys/status'' content Object ID'"/>
            <xsl:with-param name="exp" select="'/test.livcos.org/data/unit/sys/status'"/>
            <xsl:with-param name="val" select="f:object-id($dataObj/c:unit/c:sys/c:status/*/*[1])"/>
          </xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'''data/unit/sys/status'' content Object Relative Name (relative to base-uri())'"/>
        		<xsl:with-param name="exp" select="'data/unit/sys/status'"/>
        		<xsl:with-param name="val" select="f:object-relative-name($dataObj/c:unit/c:sys/c:status/*/*[1])"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'''data/unit/sys/status'' content Object Name'"/>
        		<xsl:with-param name="exp" select="'status'"/>
        		<xsl:with-param name="val" select="f:object-name($dataObj/c:unit/c:sys/c:status/*/*[1])"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'''data/unit/ObjectId'' view 1 Object ID'"/>
            <xsl:with-param name="exp" select="'/test.livcos.org/data/Intro'"/>
            <xsl:with-param name="val" select="f:object-id($dataObj/c:unit/c:ObjectId/*/*/*/*)"/>
          </xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'''data/unit/ObjectId'' view 1 Object Relative Name (relative to base-uri())'"/>
        		<xsl:with-param name="exp" select="'/test.livcos.org/data/Intro'"/>
        		<xsl:with-param name="val" select="f:object-relative-name($dataObj/c:unit/c:ObjectId/*/*/*/*)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'''data/unit/ObjectId'' view 1 Object Name'"/>
        		<xsl:with-param name="exp" select="'Intro'"/>
        		<xsl:with-param name="val" select="f:object-name($dataObj/c:unit/c:ObjectId/*/*/*/*)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'''data/unit/ObjectId'' view 2 Object ID'"/>
            <xsl:with-param name="exp" select="'/test.livcos.org/data/playground'"/>
            <xsl:with-param name="val" select="f:object-id($dataObj/c:unit/c:ObjectId/*/*/*/*/*)"/>
          </xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'''data/unit/ObjectId'' view 2 Object Relative Name (relative to base-uri())'"/>
        		<xsl:with-param name="exp" select="'/test.livcos.org/data/playground'"/>
        		<xsl:with-param name="val" select="f:object-relative-name($dataObj/c:unit/c:ObjectId/*/*/*/*/*)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'''data/unit/ObjectId'' view 2 Object Name'"/>
        		<xsl:with-param name="exp" select="'playground'"/>
        		<xsl:with-param name="val" select="f:object-name($dataObj/c:unit/c:ObjectId/*/*/*/*/*)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'''Abc Abc'' Tag Name'"/>
            <xsl:with-param name="exp" select="'Abc_Abc'"/>
            <xsl:with-param name="val" select="f:encode-for-tagname('Abc Abc')"/>
          </xsl:call-template>
          <xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'''Abc_Abc'' Tag Name'"/>
            <xsl:with-param name="exp" select="'Abc_Abc'"/>
            <xsl:with-param name="val" select="f:encode-for-tagname('Abc_Abc')"/>
          </xsl:call-template>
          <xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'''Abc$Abc'' Tag Name'"/>
            <xsl:with-param name="exp" select="'Abc_24Abc'"/>
            <xsl:with-param name="val" select="f:encode-for-tagname('Abc$Abc')"/>
          </xsl:call-template>
          <xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'''1AbcAbc'' Tag Name'"/>
            <xsl:with-param name="exp" select="'_1AbcAbc'"/>
            <xsl:with-param name="val" select="f:encode-for-tagname('1AbcAbc')"/>
          </xsl:call-template>
          <xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'''.AbcAbc'' Tag Name'"/>
            <xsl:with-param name="exp" select="'_.AbcAbc'"/>
            <xsl:with-param name="val" select="f:encode-for-tagname('.AbcAbc')"/>
          </xsl:call-template>
          <xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'''~AbcAbc'' Tag Name'"/>
            <xsl:with-param name="exp" select="'_E7AbcAbc'"/>
            <xsl:with-param name="val" select="f:encode-for-tagname('~AbcAbc')"/>
          </xsl:call-template>
          <xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'''Abc ÄÖÜ Abc'' Tag Name'"/>
            <xsl:with-param name="exp" select="'Abc__C3_84_C3_96_C3_9C_Abc'"/>
            <xsl:with-param name="val" select="f:encode-for-tagname('Abc ÄÖÜ Abc')"/>
          </xsl:call-template>
          <xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'''Abc äöü Abc'' Tag Name'"/>
            <xsl:with-param name="exp" select="'Abc__C3_A4_C3_B6_C3_BC_Abc'"/>
            <xsl:with-param name="val" select="f:encode-for-tagname('Abc äöü Abc')"/>
          </xsl:call-template>
          <xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'''Abc&lt;&gt;&amp;&quot;?+'' Tag Name'"/>
            <xsl:with-param name="exp" select="'Abc_3C_3E_26_22_3F_2B'"/>
            <xsl:with-param name="val" select="f:encode-for-tagname('Abc&lt;&gt;&amp;&quot;?+')"/>
          </xsl:call-template>
          <xsl:call-template name="test-case">
            <xsl:with-param name="title" select="'''&lt;&gt;&amp;&quot;?+'' Tag Name'"/>
            <xsl:with-param name="exp" select="'_3C_3E_26_22_3F_2B'"/>
            <xsl:with-param name="val" select="f:encode-for-tagname('&lt;&gt;&amp;&quot;?+')"/>
          </xsl:call-template>
        	<xsl:variable name="uri" select="f:uri('http://www.google.com/search?q=something#test')"/>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Test URI scheme'"/>
        		<xsl:with-param name="exp" select="'http'"/>
        		<xsl:with-param name="val" select="$uri/scheme"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Test URI host'"/>
        		<xsl:with-param name="exp" select="'www.google.com'"/>
        		<xsl:with-param name="val" select="$uri/host"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Test URI path'"/>
        		<xsl:with-param name="exp" select="'/search'"/>
        		<xsl:with-param name="val" select="$uri/path"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Test URI query'"/>
        		<xsl:with-param name="exp" select="'q=something'"/>
        		<xsl:with-param name="val" select="$uri/query"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Test URI fragment'"/>
        		<xsl:with-param name="exp" select="'test'"/>
        		<xsl:with-param name="val" select="$uri/fragment"/>
        	</xsl:call-template>
        	<xsl:variable name="js-uri" select="f:uri('javascript:alert(''Hello World'');')"/>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'JS Test URI scheme'"/>
        		<xsl:with-param name="exp" select="''"/>
        		<xsl:with-param name="val" select="$js-uri/scheme"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'JS Test URI host'"/>
        		<xsl:with-param name="exp" select="''"/>
        		<xsl:with-param name="val" select="$js-uri/host"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Relativize'"/>
        		<xsl:with-param name="exp" select="'playground.xml'"/>
        		<xsl:with-param name="val"
        			select="f:relativize-uri('/test.livcos.org/data/playground.xml','/test.livcos.org/data/playground.xml')"
        		/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Relativize'"/>
        		<xsl:with-param name="exp" select="'unit/SimpleJob.xml'"/>
        		<xsl:with-param name="val"
        			select="f:relativize-uri('/test.livcos.org/data/unit/SimpleJob.xml','/test.livcos.org/data/playground.xml')"
        		/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Node ID of root element'"/>
        		<xsl:with-param name="exp" select="'1'"/>
        		<xsl:with-param name="val" select="f:node-id(*)"/>
        	</xsl:call-template>
        	<xsl:variable name="nodeIdObj" select="doc('../../data/unit/NodeId')/*"/>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Node ID of first child node'"/>
        		<xsl:with-param name="exp" select="'1.1'"/>
        		<xsl:with-param name="val" select="f:node-id($nodeIdObj/node()[1])"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Node ID of the first child element'"/>
        		<xsl:with-param name="exp" select="'1.2'"/>
        		<xsl:with-param name="val" select="f:node-id($nodeIdObj/*[1])"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Node ID of the attribute of the first child element'"/>
        		<xsl:with-param name="exp" select="'1.2.@attr1'"/>
        		<xsl:with-param name="val" select="f:node-id($nodeIdObj/*[1]/@*)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Node ID of an entity element'"/>
        		<xsl:with-param name="exp" select="'entity_1'"/>
        		<xsl:with-param name="val" select="f:node-id($nodeIdObj//*[@id])"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Node ID of the text within an element within the entity element'"/>
        		<xsl:with-param name="exp" select="'entity_1.2.1'"/>
        		<xsl:with-param name="val" select="f:node-id($nodeIdObj//*[@id]/*/node())"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Node ID of the text within an element within the entity element'"/>
        		<xsl:with-param name="exp" select="'entity_1.2.@attr2'"/>
        		<xsl:with-param name="val" select="f:node-id($nodeIdObj//*[@id]/*/@*)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Node ID of the third child element'"/>
        		<xsl:with-param name="exp" select="'1.6'"/>
        		<xsl:with-param name="val" select="f:node-id($nodeIdObj/*[3])"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Node ID of the attribute of the third child element'"/>
        		<xsl:with-param name="exp" select="'1.6.@attr3'"/>
        		<xsl:with-param name="val" select="f:node-id($nodeIdObj/*[3]/@*)"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Node ID of the ''test'' text node'"/>
        		<xsl:with-param name="exp" select="'1.7'"/>
        		<xsl:with-param name="val" select="f:node-id($nodeIdObj/text()[normalize-space() = 'test'])"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Node ID of the comment node'"/>
        		<xsl:with-param name="exp" select="'1.8'"/>
        		<xsl:with-param name="val" select="f:node-id($nodeIdObj/comment())"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Extract path from cosmos:/test.domain/object/'"/>
        		<xsl:with-param name="exp" select="'/test.domain/object'"/>
        		<xsl:with-param name="val" select="f:extract-path('cosmos:/test.domain/object/')"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Extract path from cosmos:/test.domain/object/?query=...'"/>
        		<xsl:with-param name="exp" select="'/test.domain/object'"/>
        		<xsl:with-param name="val" select="f:extract-path('cosmos:/test.domain/object/?query=/test/test.html')"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Extract object ID from cosmos:/test.domain/object/object.test.html?query=...'"/>
        		<xsl:with-param name="exp" select="'/test.domain/object/object.test'"/>
        		<xsl:with-param name="val" select="f:extract-object-id('cosmos:/test.domain/object/object.test.html?query=/test/test.html')"/>
        	</xsl:call-template>
        	<xsl:call-template name="test-case">
        		<xsl:with-param name="title" select="'Extract object ID from test.object/object.test.html?query=...'"/>
        		<xsl:with-param name="exp" select="'test.object/object.test'"/>
        		<xsl:with-param name="val" select="f:extract-object-id('test.object/object.test.html?query=/test/test.html')"/>
        	</xsl:call-template>
        </table>
      </body>
    </html>
  </xsl:template>
  
  <xsl:template name="test-case">
    <xsl:param name="title"/>
  	<xsl:param name="exp"/>
  	<xsl:param name="exp_regExp"/>
  	<xsl:param name="val"/>
    <tr>
      <xsl:if test="($exp_regExp and not(matches($val, $exp_regExp))) 
      	or ($exp and (($exp != $val) or not($val)))">
        <xsl:attribute name="style">color: red</xsl:attribute>
      </xsl:if>
      <td><xsl:value-of select="$title"/></td>
    	<td><xsl:value-of select="$exp"/><xsl:value-of select="$exp_regExp"/></td>
      <td><xsl:value-of select="$val"/></td>
    </tr>
  </xsl:template>
  
</xsl:stylesheet>
